# 修复后的流式输出测试脚本

Write-Host "=== 修复后的流式输出测试 ===" -ForegroundColor Green

$baseUrl = "http://localhost:8082/api/ollama"

Write-Host "`n测试流式输出是否实现逐字显示..." -ForegroundColor Yellow

try {
    $body = @{
        prompt = "请详细介绍一下Spring AI框架的主要特性和优势"
    } | ConvertTo-Json

    Write-Host "发送流式请求..." -ForegroundColor Gray
    Write-Host "URL: $baseUrl/chat-stream" -ForegroundColor Cyan
    Write-Host "请求体: $body" -ForegroundColor Gray
    Write-Host "`n开始接收流式响应（应该看到逐字输出）:" -ForegroundColor Yellow
    Write-Host "=" * 60 -ForegroundColor Gray

    # 使用curl来测试流式输出，可以看到实时效果
    $curlCommand = "curl -N -X POST `"$baseUrl/chat-stream`" -H `"Content-Type: application/json`" -d '$body'"
    Write-Host "执行命令: $curlCommand" -ForegroundColor Gray
    Write-Host ""
    
    # 执行curl命令
    Invoke-Expression $curlCommand
    
    Write-Host "`n=" * 60 -ForegroundColor Gray
    Write-Host "流式测试完成" -ForegroundColor Green

} catch {
    Write-Host "测试失败: $($_.Exception.Message)" -ForegroundColor Red
}

Write-Host "`n💡 测试说明:" -ForegroundColor Magenta
Write-Host "- 如果看到文字逐个或逐词出现，说明流式输出正常工作" -ForegroundColor White
Write-Host "- 如果文字一次性全部出现，说明还有问题需要调试" -ForegroundColor White
Write-Host "- 建议同时打开浏览器访问 http://localhost:8082/stream.html 进行可视化测试" -ForegroundColor White

Write-Host "`n🔧 调试建议:" -ForegroundColor Magenta
Write-Host "1. 检查后端日志，确认每个chunk都被正确发送" -ForegroundColor White
Write-Host "2. 使用浏览器开发者工具查看Network面板的SSE连接" -ForegroundColor White
Write-Host "3. 确认Ollama服务正常运行且模型已加载" -ForegroundColor White
